#include "ui_select_kit.h"
#include "kit.h"
#include "ui_main.h"



UISelectKit::UISelectKit()
{
	UI::Panel* _panelBg = CreatePanel("bg");
	{
		UI::Sprite* ui_spr = UI::Sprite::Create(
			g_factory->CreateSprite("menu_bg"), {}, UI::Sprite::Mode::RATIO_W);
		_panelBg->Add(ui_spr);
	}
	UI::Panel* _panelTitle = CreatePanel("title");
	_panelTitle->SetPosScale({ 0.5f, 0.10f });
	{
		gcText txt = g_factory->CreateText(TR_FONT_ID_ART, 64);
		txt->SetString("选择卡组");
		UI::Text* ui_txt = UI::Text::Create(txt);
		ui_txt->SetElementData(Align::CC);
		_panelTitle->Add(ui_txt);
	}

	{// 菜单
		UI::Panel* panel = CreatePanel("menu_lb");
		panel->SetPosScale({ 0.0f, 1.0f });
		panel->SetPosPixel({ 40, -100 });
		{
			_btnBack = g_ui->CreateButtonSpriteDefault();
			_btnBack->SetSound("btn_click", "btn_over");
			_btnBack->SetString("返回");
			panel->Add(_btnBack);
		}
	}

	//
	_panel = CreatePanel("root");
	_panel->SetLocator(createLocatorX(TR_CARD_SIZE[0] + 40, 4, TR_CARD_SIZE[1] + 40));
	_panel->SetPosScale({ 0.15f, 0.5f });

	for (const Kit& kit : g_kit->GetKitAll())
	{
		UI::Panel* p = g_ui->CreatePanel();
		p->SetLocator(createLocatorZero());

		UI::Sprite* ui_spr = UI::Sprite::Create(kit.GetSprite(CardID::愚人), TR_CARD_SIZE, UI::Sprite::Mode::STATIC);
		ui_spr->SetElementData(Align::CC);
		p->Add(ui_spr);

		UI::Text* ui_txt = UI::Text::Create(g_factory->CreateText(
			TR_FONT_ID_ART, 32, ColorDef::WHITE, 1));
		ui_txt->SetString(kit.GetName());
		ui_txt->SetElementData(Align::CC);
		p->Add(ui_txt);

		UI::ButtonScale* btn = UI::ButtonScale::Create(p);
		_panel->Add(btn);
	}
}

void UISelectKit::Update()
{
	size_t index = _panel->GetClickIndex();
	if (index == 0)
	{

	}
	if (_btnBack->IsClick())
	{
		g_scene->Del(GetName());
		g_scene->Add("main", new UIMain);
	}
}
